﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Collections;

namespace MM.Common
{
    public class Common
    {
        #region Page JS
        public static void PageStartAlert(Page page, string text)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "ClientScriptAlert", "<script type=\"text/javascript\">window.alert(\"" + text.Replace("\"", "\\\"") + "\");</script>");
        }
        public static void PageReload(Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "ClientScriptReload", "<script type=\"text/javascript\">window.location.href=window.location.href;</script>");
        }
        public static void PageRedirect(Page page, string targetUrl)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "ClientScriptRedirect", "<script type=\"text/javascript\">window.location.href=\"" + targetUrl.Replace('"', '\'') + "\";</script>");
        }
        public static void PageAlertAndRedirect(Page page, string text, string targetUrl)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "ClientScriptRedirect", "<script type=\"text/javascript\">window.alert(\"" + text.Replace("\"", "\\\"") + "\");window.location.href=\"" + targetUrl.Replace('"', '\'') + "\";</script>");
        }
        public static void PageOpen(Page page, string targetUrl)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "ClientScriptRedirect", "<script type=\"text/javascript\">window.open(\"" + targetUrl.Replace('"', '\'') + "\");</script>");
        }
        #endregion
    }
}
